package org.compiere.model;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

public class Mzuser extends X_zuser{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 868046968655237699L;
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (Mzuser.class);

	public Mzuser(Properties ctx, int zuser_ID, String trxName) {
		super(ctx, zuser_ID, trxName);
		
	}

	public Mzuser(Properties ctx, ResultSet rs, String trxName) {
		super(ctx, rs, trxName);
		
	}


	public static Mzuser login(String login, String pass){
		
		Mzuser zuser = null;
		
		String sql = "SELECT zuser_id FROM adempiere.zuser " +
				"		where trim(iin) = ?	" +
				"		and trim(password) = ? ";

		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try
		{
			pstmt = DB.prepareStatement (sql, null);
			pstmt.setString(1, login);
			pstmt.setString(2, pass);
			rs = pstmt.executeQuery();
			if (rs.next())
			{
				return new Mzuser(Env.getCtx(), rs.getInt(1), null); 
			}
		}
		catch (SQLException e)
		{
			s_log.log(Level.SEVERE, sql, e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}
		
		return zuser;
		
	}
	
}
